package JavaSE.ThreadLearning.ThreadYield;

/**
 *  学习 线程礼让 yield()
 *      可以明显看出，非常大的几率在打印5和6之间，会有另一个线程插入
 *      也就意味着在那之间前面的线程礼让了
 */
public class Demo {
    public static void main(String[] args) throws InterruptedException {
        Boom zs = new Boom("张三");
        Clap clap = new Clap();
        zs.start();
        clap.start();
    }
}

class Boom extends Thread {
    String name;
    Boom(String name) {
        super(name);
        this.name = name;
    }
    public void boom() {
        System.out.println("1");
        System.out.println("2");
        System.out.println("3");
        System.out.println("4");
        System.out.println("5");
        yield();
        System.out.println("6");
        System.out.println("7");
        System.out.println("8");
        System.out.println("9");
        System.out.println("10");
        System.out.println("11");
        System.out.println("12");
    }

    @Override
    public void run() {
        boom();
    }
}

class Clap extends Thread {
    public static void clap() {
        for (int i = 0; i < 10; i++) {
            System.out.println("第" + i + "次鼓掌");
        }
    }

    @Override
    public void run() {
        clap();
    }
}
